<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin();
$this->model('member')->up_tixianfee();
if($_RQ['op']=='get'){
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$return['allmoney']=pdo_getsum('jy_newganfee_commission',array('mid'=>$_SESSION['uid']),'money');
	$return['member']=$member;
	$member=$this->get('member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$level=$this->get('level',array('id'=>$member['level_id']));
	$parameter=array(
			'params'=>array('uniacid'=>$_SESSION['uniacid'],'level >'=>$level['level']),
			'orderby'=>'level asc',
			'limit'=>'1',
	);
	$levels=$this->get_list('level',$parameter);
	$next_level=$levels[0];
	if($level['id']){
		$commissions=json_decode($level['commissions'],true);
		$tips='您当前等级是《'.$level['title'].'》,享受直推佣金['.$commissions['commission_0'].'],享受间推佣金['.$commissions['commission_0'].'],享受上级佣金['.$commissions['shangji'].']（不同的商品，所有差异！）';
	}else{
		$commissions=$next_level['commissions']=json_decode($next_level['commissions'],true);
		$tips='您当前等级是《默认等级》，再推荐['.$next_level['fennum'].']人,可升级为《'.$next_level['title'].'》,享受直推佣金['.$commissions['commission_0'].'],享受间推佣金['.$commissions['commission_0'].'],享受上级佣金['.$commissions['shangji'].']（不同的商品，所有差异！）';
	}
	$return['tips']=$tips;
	$return['level']=$level?:array();
	$return['params']['type']=$_RQ['type']?:2;
	$next_level['level']=$next_level['level']?:0;
	$return['levels']=$this->pdo_getall('level',array('level >='=>$next_level['level'],'uniacid'=>$_SESSION['uniacid']),array('id','title','conditions'),'id');
	$return['post']=array();
	foreach($return['levels'] as $k=>&$lv){
		$lv['conditions']=json_decode($lv['conditions'],true);
		$lv['fee']=$lv['conditions']['buy_credit']?:0;
		if(!$lv['fee'] || !$lv['conditions']['credit_type']){
			unset($return['levels'][$k]);
			continue;
		}
		$lv['credittitle']=$this->gift_type[$lv['conditions']['credit_type']];
		if(empty($return['post'])){
			$return['post']=$lv;
		}
	}
	set_html('title','我的任务');
	exi($return);
}
if($_RQ['op']=='post'){
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$post=get_postdata();
	if(!$post['id']){
		exi('请选择要兑换的等级！','erroe');
	}
	$level=$this->get('level',array('id'=>$post['id'],'uniacid'=>$_SESSION['uniacid']));
	$level['conditions']=json_decode($level['conditions'],true);
	$credit_type=$level['conditions']['credit_type'];
	if($member['credit'.$credit_type]<$level['conditions']['buy_credit']){
		exi('当前余额不足，兑换失败！','erroe');
	}
	$nowmember=$this->get('member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	if($nowmember['level_id']==$level['id']){
		exi('你已经是该等级了，不能兑换！','erroe');
	}
	$this->pdo_update('member',array('level_id'=>$level['id']),array('mid'=>$_SESSION['uid']));
	model('core/member')->member_credit($_SESSION['uid'],'credit'.$credit_type,$level['conditions']['buy_credit'],'','jy_newganfee','兑换等级：'.$level['title']);
	exi('兑换等级成功！');
}
if($_RQ['op']=='password'){
	$post=get_postdata();
	if(!$post['password']){
		exi('请输入支付密码！','erroe');
	}
	pdo_update('core_members',array('paypassword'=>$post['password']),array('id'=>$_SESSION['uid']));
	exi('设置成功！');
}
if($_RQ['op']=='fenlist'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']);
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getslice('jy_newganfee_commission',$params,array($pindex,$psize),$total,$fields,'',$orderby);	
	foreach($return['list'] as &$v){
			$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
			$v['typetitle']=$this->fen_type[$v['type']];
			$v['statustitle']=$this->commission_status[$v['status']];
			$v['ordermid']=pdo_getcolumn('jy_weishop_order',array('id'=>intval($v['orderid'])),'mid');
			$v['member']=cfc('core')->member_show($v['ordermid']);
	}
	exi($return);
}